package com.example.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.mapper.ClassTypeMapper;
import com.example.demo.model.entity.ClassTypeEntity;
import com.example.demo.model.entity.NewsEntity;
import com.example.demo.model.param.ClassTypeParam;
import com.example.demo.model.vo.ResponseVo;
import com.example.demo.service.ClassTypeService;
import com.example.demo.untils.BuildResponseUtils;
import com.example.demo.untils.CommonQueryPageUntils;
import com.example.demo.untils.PageBean;
import com.example.demo.untils.PageVoUtils;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.javassist.bytecode.SignatureAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ClassTypeController {

    @Autowired
    private ClassTypeService classTypeService;

    @PostMapping("/addClassType")
    public ResponseVo<?> addClassType(@RequestBody ClassTypeEntity classTypeEntity){
        return classTypeService.save(classTypeEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/getClassTypeList")
    public ResponseVo<?> getClassTypeList(@RequestBody ClassTypeParam classTypeParam){
        PageInfo pageInfo = classTypeService.selectClassTypeList(classTypeParam);
        PageBean pageBean = PageVoUtils.convertTopageVo(pageInfo);
        return BuildResponseUtils.buildResponse(pageBean);
    }



    @GetMapping("/deleteClassType")
    public ResponseVo<?> deleteClassType(@RequestParam("id") Integer id){
        return classTypeService.removeById(id) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/updateClassType")
    public ResponseVo<?> updateClassType(@RequestBody ClassTypeEntity classTypeEntity){
        return classTypeService.updateById(classTypeEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @GetMapping("/getAllClassType")
    public ResponseVo<?> getAllClassType(){
        return BuildResponseUtils.buildResponse(classTypeService.list());
    }



}
